package com.icexxx.ice_browser;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PanelManager {
    public static JPanel create() {
        return new JPanel();
    }

    public static JPanel createHistoryList() {// left
        JPanel panel = new JPanel();
        panel.setSize(110, 620);
        JPanel listPanel = createListPanel();
        JScrollPane scrollPane = new JScrollPane(listPanel);
        Dimension preferredSize = new Dimension(205, 853);
        scrollPane.setPreferredSize(preferredSize);
        panel.add(scrollPane);
        panel.setBackground(Color.RED);
        return panel;
    }

    private static JPanel createListPanel() {
        JPanel panel = new JPanel();
        Dimension preferredSize = new Dimension(200, 850);
        panel.setPreferredSize(preferredSize);
        JList<String> jlist = ListManager.createList();
        panel.add(jlist);
        return panel;
    }

    public static JPanel createMainPanel() {// right
        JPanel panel = new JPanel();
        panel.setBackground(Color.BLUE);
        BorderLayout borderLayout = new BorderLayout();
        panel.setLayout(borderLayout);
        JPanel topPanel = createTopPanel();// right-上3行
        JPanel createCenterPanel = createCenterPanel();
        panel.add(createCenterPanel, BorderLayout.CENTER);
        panel.add(topPanel, BorderLayout.NORTH);
        return panel;
    }

    private static JPanel createTopPanel() {
        JPanel createAddressPanel = createAddressPanel();// 第一行
        JPanel createParamPanel = createParamPanel();// 第二行
        JPanel createClipboardPanel = createClipboardPanel();// 第三行
        JPanel panel = new JPanel();
        Dimension preferredSize = new Dimension(300, 250);
        panel.setPreferredSize(preferredSize);
        BorderLayout borderLayout = new BorderLayout();
        panel.setLayout(borderLayout);
        panel.add(createAddressPanel, BorderLayout.NORTH);
        panel.add(createParamPanel, BorderLayout.CENTER);
        panel.add(createClipboardPanel, BorderLayout.SOUTH);
        panel.setBackground(new Color(50, 50, 150));
        return panel;
    }

    public static JPanel createAddressPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.GREEN);
        BorderLayout borderLayout = new BorderLayout();
        panel.setLayout(borderLayout);
        JPanel requestMethodPanel = createRequestMethodPanel();
        JPanel requestAddressPanel = createRequestAddressPanel();
        JPanel requestCommitPanel = createRequestCommitPanel();
        panel.add(requestMethodPanel, BorderLayout.WEST);
        panel.add(requestAddressPanel, BorderLayout.CENTER);
        panel.add(requestCommitPanel, BorderLayout.EAST);
        return panel;
    }

    private static JPanel createParamPanel() {
        JPanel panel = new JPanel();
        panel.setSize(10, 10);
        Dimension preferredSize = new Dimension(10, 10);
        panel.setPreferredSize(preferredSize);
        panel.setBackground(Color.MAGENTA);
        FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 1, 1);
        panel.setLayout(flowLayout);
        JTextArea editText = EditManager.createParamTextArea();
        panel.add(editText, BorderLayout.CENTER);
        return panel;
    }

    private static JPanel createRequestCommitPanel() {
        JPanel panel = new JPanel();
        JButton button = ButtonManager.createRequestCommitButton();
        panel.add(button);
        panel.setBackground(Color.BLUE);
        return panel;
    }

    private static JPanel createRequestAddressPanel() {
        JPanel panel = new JPanel();
        panel.setSize(200, 40);
        Dimension preferredSize = new Dimension(200, 40);
        panel.setPreferredSize(preferredSize);
        FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 1, 1);
        panel.setLayout(flowLayout);
        panel.setBackground(Color.ORANGE);
        JTextField editText = EditManager.createRequestAddressEditText();
        panel.add(editText);
        return panel;
    }

    private static JPanel createCopyContentPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.BLACK);
        JButton button = ButtonManager.createCopyContentButton();
        panel.add(button);
        return panel;
    }

    private static JPanel createCopyUrlPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.GREEN);
        JButton button = ButtonManager.createCopyUrlButton();
        panel.add(button);
        return panel;
    }

    private static JPanel createParseUrlPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.DARK_GRAY);
        JButton button = ButtonManager.createParseUrlButton();
        panel.add(button);
        return panel;
    }

    private static JPanel createRequestMethodPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.YELLOW);
        Dimension preferredSize = new Dimension(80, 40);
        panel.setPreferredSize(preferredSize);
        JComboBox<String> jComboBox = ListManager.createRequestMethodList();
        panel.add(jComboBox);
        return panel;
    }

    public static JPanel createClipboardPanel() {
        JPanel panel = new JPanel();
        panel.setSize(500, 100);
        panel.setBackground(Color.GRAY);
        BorderLayout borderLayout = new BorderLayout();
        panel.setLayout(borderLayout);
        JPanel parseUrlPanel = createParseUrlPanel();
        JPanel contentPanel = createCopyContentPanel();
        JPanel copyUrlPanel = createCopyUrlPanel();
        panel.add(parseUrlPanel, BorderLayout.WEST);
        panel.add(contentPanel, BorderLayout.CENTER);
        panel.add(copyUrlPanel, BorderLayout.EAST);
        return panel;
    }

    public static JPanel createCenterPanel() {
        JPanel panel = new JPanel();
        FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 1, 1);
        panel.setLayout(flowLayout);
        panel.setBackground(Color.ORANGE);
        JTextArea editText = EditManager.createCenterTextArea();
        panel.add(editText);
        return panel;
    }
}
